<?php
abstract class BaseModelDBO {
	/**
     * The pdo resource are reffered.
     *
     * @var static object
    */
	protected  $_link = NULL;
	/**
     * The pdo resources are reffered.
     *
     * @var array mysqli object
    */
	protected static $links = array();
    /**
     * The Database's host name.
     *
     * @var string
    */
	protected $_host = NULL;
    /**
     * The Database's access user name.
     *
     * @var string
    */	
	protected $_user = NULL;
    /**
     * The Database's access user's password.
     *
     * @var string
    */
	protected $_passwd = NULL;
    /**
     * The Database's using database name.
     *
     * @var string
    */
	protected $_dbName = NULL;
    /**
     * The Database's connecting port.
     * 
     * @var unsigned integer
    */
	protected $_port = NULL;
    /**
     * The unique key index of the link object
     *
     * @var string
    */
	protected $_uniqueDBKey  = NULL;
	
	
    /**
     * Get the using database name.
     *
     * @return string 
    */
    public function getDataBaseName() {
        return $this->_dbName;
    }
    /**
     * Get the using database host name.
     *
     * @return string 
    */
    protected function getHost() {
        return $this->_host;
    }
    /**
     * Get the using database user name.
     *
     * @return string 
    */
    protected function getUser() {
        return $this->_user;
    }
	/**
	 * Get the using database user passwd
	 *
	 * @return string
	*/
	protected function getPasswd() {
		return $this->_passwd;
	}
    /**
     * Get the using database port.
     *
     * @return unsigned integer 
    */
    protected function getPort() {
        return $this->_port;
    }
    /**
     * Seck the mysqli link unique key.
     *
    */
    protected function _setUniqueKey() {
        $this->_uniqueDBKey = "{$this->_host}-{$this->_user}-{$this->_passwd}-{$this->_dbname}-{$this->_port}";
    }
    /**
     * Get the mysqli link unique key.
     *
     * @return string 
    */
    protected function _getUniqueKey() {
        return $this->_uniqueDBKey;
    }
	/**
	 * check the current db link handle is available.
	 *
	 * @return TRUE or FALSE
	*/
	protected function checkLink($model) {
		if( !self::$links[$this->_getUniqueKey()] ) {
			$dcf = DBConfig::get($this->_dbName, $model);
			extract($dcf);
			$this->connector($host, $user, $passwd, $dbname, $port);
		}
		return TRUE;
	}
	/**
	 * get multi-array attributes
	 * select,show query
	 * @return TRUE OR FALSE
	*/
	abstract public function getAttributes($query, &$attrs=array());
	
	/**
	 * get the first element from query result
	 * 
	 * @return TRUE OR FALSE
	*/
	abstract public function getOneAttribute($query, &$val=NULL);
	/**
	 * execute the update,insert,replace,etc query
	 *
	 * @return TRUE OR FALSE
	*/
	abstract public function runQuery($query);
	/**
	 * close db link handle
	 * 
	 * @return TRUE or FALSE
	*/
	abstract public function close();
	/**
	 * get the last insert id
	 * 
	 * @return the id
	*/
	abstract public function getInsertId();
	/**
	 * get the affect rows
	 *
	 * @return unsigned integer
	*/
	abstract public function getAffectedRows();
	/**
	 * get the query error information
	 *
	 * @return string
	*/
	abstract public function errorInfo();
	/**
	 * get the query error number
	 *
	 * @return integer
	*/
	abstract public function errorCode();
}
?>
